package com.cloud.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

public class MyProfilePage extends AnyPage {


    //Constructor
    public MyProfilePage(PageManager pages) {
        super(pages);
    }


    //Page elements
    @FindBy(xpath = "//*[@id=\"fixedContainer\"]/div[3]/table[1]/tbody/tr[1]/td[2]")
    private WebElement email;

    @FindBy(xpath = "//*[@id=\"fixedContainer\"]/div[3]/table[1]/tbody/tr[2]/td[2]")
    private WebElement firstName;

    @FindBy(xpath = "//*[@id=\"fixedContainer\"]/div[3]/table[1]/tbody/tr[3]/td[2]")
    private WebElement lastName;


    //Methods
    public MyProfilePage ensurePageLoaded() {
        wait.until(presenceOfElementLocated(By.linkText("Edit profile")));
        return this;
    }

    public boolean isLoaded() {
        try {
            wait.until(presenceOfElementLocated(By.linkText("Edit profile")));
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    public String getEmail() {
        return email.getText();
    }

    public String getFirstName() {
        return firstName.getText();
    }

    public String getLastName() {
        return lastName.getText();
    }

}
